

package com.ourteam.education.dao.impl ;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.beanutils.PropertyUtils;

import org.springframework.jdbc.core.RowMapper;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;


import com.ourteam.education.dao.CoursePrice;
import com.ourteam.education.dao.CoursePriceDAOQueryBean;
import com.ourteam.education.dao.ICoursePriceDAO;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2019-09-22 15:15:11
  * Warning ! This file will be overwrite when regenerate !
  * 
 */

public class AbstractCoursePriceDAOJdbcImpl 
    extends AbstractSpringDAO implements ICoursePriceDAO{
    
            
    	
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
						
			
			
								
			
			
				
		
	    
    					
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	
    public static final String[] ENTITY_FIELDS = new String[] { Id,CourseDefineId,CampusId,Price,PriceUnit,Status,Remarks,DeleteFlag,Ammount,ChargingMode,CourseName,CampusName };
	
	public static final String[] ENTITY_PROPERTIES = new String[] {_DataObjectProperty.Id,_DataObjectProperty.CourseDefineId,_DataObjectProperty.CampusId,_DataObjectProperty.Price,_DataObjectProperty.PriceUnit,_DataObjectProperty.Status,_DataObjectProperty.Remarks,_DataObjectProperty.DeleteFlag,_DataObjectProperty.Ammount,_DataObjectProperty.ChargingMode,_DataObjectProperty.CourseName,_DataObjectProperty.CampusName};
	
	public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
	
	public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
	
	public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};
	
	private static String relatedJoinSQL = null;
	
	private static String basicFilterSQL = null;
	
	private DataAccessObjectHelper<CoursePrice, CoursePriceDAOQueryBean> daoHelper;
	
	public AbstractCoursePriceDAOJdbcImpl() {
		super();
		daoHelper = new DataAccessObjectHelper<CoursePrice, CoursePriceDAOQueryBean>(this);
	}
	
	protected String getEntityName() {
		return EntityName;
	}

	protected String[] getEntityFields() {
		return ENTITY_FIELDS;
	}

	protected String[] getEntityProperties() {
		return ENTITY_PROPERTIES;
	}

	protected String[] getEntityPKFields() {
		return ENTITY_PK_FIELDS;
	}
	
	protected String[] getEntityAutoGenPKFields(){
		return ENTITY_AUTO_GEN_PK_FIELDS;
	}
	
	
	protected String[] getEntityUniqueFields() {
		return ENTITY_UNIQUE_FIELDS;
	}
	
	protected String getBaiscQueryFilter(){
	
		if(basicFilterSQL == null){
                        StringBuffer basicFilterSQLbuffer = new StringBuffer();
						
			basicFilterSQLbuffer.append(DeleteFlag).append("=  0  ");
			
						
						
			basicFilterSQL = basicFilterSQLbuffer.toString();
		}
		
		return basicFilterSQL;
	}
	
	protected String getRelatedJoinSQL(){
		
		if(relatedJoinSQL == null){
			StringBuffer relatedJoinSQLBuffer = new StringBuffer();
			
						
			            
            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                .append(com.ourteam.education.dao.ICourseDefineDAO.EntityName)
                .append(" RELATED_2FL4V4_CourseDefine ");
			
			 relatedJoinSQLBuffer.append(" ON ( ");
								                				
				relatedJoinSQLBuffer.append(StringUtils.replace(com.ourteam.education.dao.ICourseDefineDAO.Id,com.ourteam.education.dao.ICourseDefineDAO.EntityName + ".","RELATED_2FL4V4_CourseDefine."));
				relatedJoinSQLBuffer.append(" = ").append(CourseDefineId);
					
								                
                                                
                                
                                
                    			
    			relatedJoinSQLBuffer.append(" AND ");  
    			
    			                
                relatedJoinSQLBuffer.append(StringUtils.replace(com.ourteam.education.dao.ICourseDefineDAO.DeleteFlag,com.ourteam.education.dao.ICourseDefineDAO.EntityName + ".", "RELATED_2FL4V4_CourseDefine.")).append(" ").append("=  0  ");
			
                			
			    			
			
            relatedJoinSQLBuffer.append(" ) ");
						
			            
            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                .append(com.ourteam.education.dao.ICampusDAO.EntityName)
                .append(" RELATED_MBBIC3_Campus ");
			
			 relatedJoinSQLBuffer.append(" ON ( ");
								                				
				relatedJoinSQLBuffer.append(StringUtils.replace(com.ourteam.education.dao.ICampusDAO.Id,com.ourteam.education.dao.ICampusDAO.EntityName + ".","RELATED_MBBIC3_Campus."));
				relatedJoinSQLBuffer.append(" = ").append(CampusId);
					
								                
                                                
                                
                                
                    			
    			relatedJoinSQLBuffer.append(" AND ");  
    			
    			                
                relatedJoinSQLBuffer.append(StringUtils.replace(com.ourteam.education.dao.ICampusDAO.DeleteFlag,com.ourteam.education.dao.ICampusDAO.EntityName + ".", "RELATED_MBBIC3_Campus.")).append(" ").append("=  0  ");
			
                			
			    			
			
            relatedJoinSQLBuffer.append(" ) ");
						
			relatedJoinSQL = relatedJoinSQLBuffer.toString();
		}
		
		return relatedJoinSQL;
	}
	
    /**
	 * Check Data Unique
	 * @param aCoursePrice
	 * @throws Exception
	 */
	public boolean checkIsUnique(CoursePrice aCoursePrice) throws Exception{
	
		if(aCoursePrice == null){
			return true;
		}
	
		List valueList = new ArrayList();

		List pkValueList = new ArrayList();
		
		                
				
	    		
		pkValueList.add(aCoursePrice.getId());
				
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
				
		return isUnique(valueList.toArray(new Object[valueList.size()]), pkValueList
				.toArray(new Object[pkValueList.size()]));
	
	}
	
	/**
	 * Insert Data
	 * @param aCoursePrice
	 * @throws Exception
	 */
	public void insert(CoursePrice aCoursePrice) throws Exception{
		
						
		PropertyUtils.setProperty(aCoursePrice,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("0",int.class));
				
				
		super.doInsert(aCoursePrice);

	}

    /**
	 * Batch Insert Datas
	 * @param aCoursePrice
	 * @throws Exception
	 */
	public void batchInsert(CoursePrice[] aCoursePrices) throws Exception{
		
		 super.doBatchInsert(aCoursePrices);
		
	}

    /**
	 * Delete Data
	 * @param  final long id	 *
	 * @throws Exception
	 */
	public void delete( final long id ) throws Exception{

				
		CoursePrice tempCoursePrice = findById( id);
		
						
		PropertyUtils.setProperty(tempCoursePrice,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("1",int.class));
				
				
		update(tempCoursePrice);
				
	}
	
	/**
	 * Delete Datas
	 * @param queryBean 
	 * @throws Exception
	 */
	public void delete(CoursePriceDAOQueryBean queryBean) throws Exception{
	
				
		CoursePrice tempCoursePrice = new CoursePrice();
		
				
				
	    PropertyUtils.setProperty(tempCoursePrice,_DataObjectProperty.DeleteFlag,org.apache.commons.beanutils.ConvertUtils.convert("1",int.class));
				
				
		update(tempCoursePrice,queryBean);
				
	}
	
	public void delete(CoursePrice aCoursePrice) throws Exception {
				
				
									
						
					
				
		delete(aCoursePrice.getId());
		
	}
	
	/**
	 * Update Data Selective
	 * @param aCoursePrice
	 * @throws Exception
	 */
	public void update(CoursePrice aCoursePrice) throws Exception{
		
						
											
				
				
		if(aCoursePrice.getId() == 0){
			throw new Exception("Can not update object data whith out primary key value");
		}
				
		super.doUpdate(aCoursePrice);
		
		CoursePrice tempObj = findById(aCoursePrice.getId());
		
		if(tempObj != null){
			PropertyUtils.copyProperties(aCoursePrice, tempObj);
		}
	}
	
	/**
	 * Batch Update Datas
	 * @param aCoursePrices[]
	 * @throws Exception
	 */
	public void batchUpdate(CoursePrice[] aCoursePrices) throws Exception{
		
		super.doBatchUpdate(aCoursePrices);

	}

    /**
	 * Update Data By Condictions
	 * @param aCoursePrice
	 * @param aValueCriteria 
	 * @param aTransaction
	 * @throws Exception
	 */
	public void update(CoursePrice aCoursePrice, CoursePriceDAOQueryBean aQueryBean) throws Exception{
		
				
		super.doUpdateByQuery(aCoursePrice, aQueryBean);
		
	}
	
	/**
	 * Update Data By Condictions
	 * @param aQueryBean
	 * @throws Exception
	 */
	public void update(CoursePriceDAOQueryBean aQueryBean) throws Exception {
		super.doUpdateByQuery(aQueryBean);
	}


    protected void checkNullValue(CoursePrice aCoursePrice) throws Exception{	
																																																	
		if(aCoursePrice.getCourseName() == null){
			throw new Exception("The CoursePrice.courseName value is not allow NULL");
		}
													
		if(aCoursePrice.getCampusName() == null){
			throw new Exception("The CoursePrice.campusName value is not allow NULL");
		}
																													
		if(aCoursePrice.getChargingMode() == null){
			throw new Exception("The CoursePrice.chargingMode value is not allow NULL");
		}
								
	}
	
	/**
	 * Get Data By ID
	 * @param  final long id	 * @return  ${businessObject.name}
	 * @throws Exception
	 */
	public CoursePrice findById( final long id) throws Exception{
		
		    	                
    	    	                		
		CoursePriceDAOQueryBean queryBean = new CoursePriceDAOQueryBean();
		
		CoursePriceDAOQueryBean.Criteria  criteria = queryBean.createCriteria();
	
		                

		criteria.andIdEqualTo(id);
        
        
		//queryBean.setDistinct(true);
		
		CoursePrice[] CoursePrices = query(queryBean);
		
		if(CoursePrices.length == 0){
			return null;
		}
		else{
			return CoursePrices[0];
		}
		
	}

    /**
	 * Query Data
	 * @param queryBean
	 * @return CoursePrice[]
	 * @throws Exception
	 */
	public CoursePrice[] query(CoursePriceDAOQueryBean queryBean) throws Exception{
				
		List result = super
				.doQuery(queryBean, new JdbcCoursePriceRowMapper());

		return (CoursePrice[]) result.toArray(new CoursePrice[result.size()]);
	}
	
	/**
	 * Query ${businessObject.name} Selective
	 * @param queryBean
	 * @return Map[]
	 * @model
	 * @throws Exception
	 */
	public Map<String,Object>[] querySelective(CoursePriceDAOQueryBean queryBean)  throws Exception{
		
		if(queryBean.getSelectProperties().isEmpty()){
			queryBean.addAllSelectProperties();
		}
		
		return super.doQuerySelective(queryBean);
		
	}
	
	/**
	 * Query Data Count
	 * @param queryBean
	 * @return int
	 * @throws Exception
	 */
	public int queryCount(CoursePriceDAOQueryBean queryBean) throws Exception{
		
		return super.doQueryCount(queryBean);
		
	}
	
	public void synchronize(CoursePrice[] aCoursePrices, CoursePriceDAOQueryBean queryBean)
			throws Exception {
		daoHelper.synchronize(aCoursePrices,queryBean);
		
	}

	public void synchronize(CoursePrice[] aCoursePrices,
			CoursePriceDAOQueryBean queryBean,
			net.dao.IDataAccessInterface.ISynchronizeCallback<CoursePrice> callBack)
			throws Exception {
		daoHelper.synchronize(aCoursePrices,queryBean,callBack);
	}

    
     public static class JdbcCoursePriceRowMapper implements
			RowMapper<CoursePrice> {

		public CoursePrice mapRow(ResultSet resultSet, int arg1) throws SQLException {
			CoursePrice object = new CoursePrice();

			int columnIndex = 1;
			
			int __dataType;
			
			try{
													
	            	            
				Object id = null;
				
								
				id =  resultSet.getObject(columnIndex++);
				
				               
				object.setIdNull(resultSet.getBoolean(columnIndex++));
				
				if(id != null){
				
                    setBeanValue(object, _DataObjectProperty.Id,id);
				}
				
					
	            	            
				Object courseDefineId = null;
				
								
				courseDefineId =  resultSet.getObject(columnIndex++);
				
				               
				object.setCourseDefineIdNull(resultSet.getBoolean(columnIndex++));
				
				if(courseDefineId != null){
				
                    setBeanValue(object, _DataObjectProperty.CourseDefineId,courseDefineId);
				}
				
					
	            	            
				Object campusId = null;
				
								
				campusId =  resultSet.getObject(columnIndex++);
				
				               
				object.setCampusIdNull(resultSet.getBoolean(columnIndex++));
				
				if(campusId != null){
				
                    setBeanValue(object, _DataObjectProperty.CampusId,campusId);
				}
				
					
	            	            
				Object price = null;
				
								
				price =  resultSet.getObject(columnIndex++);
				
				               
				object.setPriceNull(resultSet.getBoolean(columnIndex++));
				
				if(price != null){
				
                    setBeanValue(object, _DataObjectProperty.Price,price);
				}
				
					
	            	            
				Object priceUnit = null;
				
								
				priceUnit =  resultSet.getObject(columnIndex++);
				
				               
				object.setPriceUnitNull(resultSet.getBoolean(columnIndex++));
				
				if(priceUnit != null){
				
                    setBeanValue(object, _DataObjectProperty.PriceUnit,priceUnit);
				}
				
					
	            	            
				Object status = null;
				
								
				status =  resultSet.getObject(columnIndex++);
				
				               
				object.setStatusNull(resultSet.getBoolean(columnIndex++));
				
				if(status != null){
				
                    setBeanValue(object, _DataObjectProperty.Status,status);
				}
				
					
	            	            
				Object remarks = null;
				
								
				remarks =  resultSet.getObject(columnIndex++);
				
				               
				object.setRemarksNull(resultSet.getBoolean(columnIndex++));
				
				if(remarks != null){
				
                    setBeanValue(object, _DataObjectProperty.Remarks,remarks);
				}
				
					
	            	            
				Object deleteFlag = null;
				
								
				deleteFlag =  resultSet.getObject(columnIndex++);
				
				               
				object.setDeleteFlagNull(resultSet.getBoolean(columnIndex++));
				
				if(deleteFlag != null){
				
                    setBeanValue(object, _DataObjectProperty.DeleteFlag,deleteFlag);
				}
				
					
	            	            
				Object ammount = null;
				
								
				ammount =  resultSet.getObject(columnIndex++);
				
				               
				object.setAmmountNull(resultSet.getBoolean(columnIndex++));
				
				if(ammount != null){
				
                    setBeanValue(object, _DataObjectProperty.Ammount,ammount);
				}
				
					
	            	            
				Object chargingMode = null;
				
								
				chargingMode =  resultSet.getObject(columnIndex++);
				
				               
				object.setChargingModeNull(resultSet.getBoolean(columnIndex++));
				
				if(chargingMode != null){
				
                    setBeanValue(object, _DataObjectProperty.ChargingMode,chargingMode);
				}
				
								
				            	            	            					            	            	
	            	            
				Object courseName = null;
				
								
				courseName =  resultSet.getObject(columnIndex++);
				
				               
				object.setCourseNameNull(resultSet.getBoolean(columnIndex++));
				
				if(courseName != null){
				
                    setBeanValue(object, _DataObjectProperty.CourseName,courseName);
				}
				
												            	            	            					            	            	
	            	            
				Object campusName = null;
				
								
				campusName =  resultSet.getObject(columnIndex++);
				
				               
				object.setCampusNameNull(resultSet.getBoolean(columnIndex++));
				
				if(campusName != null){
				
                    setBeanValue(object, _DataObjectProperty.CampusName,campusName);
				}
				
																
				return object;
			}catch(Exception e){
				throw new SQLException(e.getMessage());
			}
		}

	}
	
}